package com.spider.page;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.spider.pool.UriQueueScheduler;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @author β世界
 * Created on 21:50
 * @Description Json类型结果处理类
 */
public class JsonPage extends ResultPage {

    private JSONObject jsonObject;

    public JsonPage(CloseableHttpResponse response, HttpRequestBase httpRequestBase, UriQueueScheduler uriQueueScheduler) {
        super(response, httpRequestBase, uriQueueScheduler);
        try {
            // 将结果转换为JSON对象
            jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }

    @Override
    public JSONObject getContent() {
        return jsonObject;
    }

    @Override
    public String toString() {
        return jsonObject.toJSONString();
    }
}
